package dev.xesam.androidkit.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

/**
 * 常用 Intent
 * Created by xe on 15-4-9.
 */
public final class IntentUtil {
    /**
     * 应用市场
     */
    public static void toMarket(Context context) {
        String packageName = context.getPackageName();
        Uri uri = Uri.parse("market://details?id=" + packageName);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        try {
            context.startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 默认浏览器
     */
    public static void defaultBrowser(Context context, String uriStr) {
        if (!uriStr.startsWith("http")) {
            uriStr = "http://" + uriStr;
        }
        Uri uri = Uri.parse(uriStr);
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        context.startActivity(intent);
    }

    /**
     * 选择图片
     */
    public static void chooseImage(Activity activity, String title, int requestCode) {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_PICK);
        Intent chooser = Intent.createChooser(intent, title);
        ActivityUtil.startActivityForResult(activity, chooser, requestCode);
    }
}
